package com.campus.controller.admin;

import com.campus.pojo.dto.StudentDormDTO;
import com.campus.pojo.dto.StudentDormPageQueryDTO;
import com.campus.result.PageResult;
import com.campus.result.Result;
import com.campus.service.StudentDormSharedService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/studentDorm")
@Slf4j
@Tag(name = "学生住宿管理")
@RequiredArgsConstructor
public class StudentDormSharedController {

    private final StudentDormSharedService dormSharedService;

    /**
     * 学生宿舍信息分页查询
     * @param studentDormPageQueryDTO
     * @return
     */
    @Operation(summary = "学生宿舍信息分页查询")
    @Parameter(name = "studentDormPageQueryDTO", description = "分页查询条件")
    @GetMapping
    public Result page(StudentDormPageQueryDTO studentDormPageQueryDTO){
      log.info("学生宿舍信息分页查询：{}", studentDormPageQueryDTO);
      PageResult pageResult = dormSharedService.pageStudentDorm(studentDormPageQueryDTO);
      return Result.success(pageResult);
    }

    /**
     * 根据宿舍id查询
     * @param id
     * @return
     */
    @Operation(summary = "根据宿舍id查询")
    @Parameter(name = "id", description = "宿舍id")
    @GetMapping("/{id}")
    public Result queueByDormId(@PathVariable Integer id){
        log.info("根据宿舍id查询:{}",  id);
        // TODO dormSharedService.queueByDormId(id);
        return Result.success();
    }

    /**
     * 添加学生宿舍信息,自动删除old数据
     * @return
     */
    @Operation(summary = "添加学生宿舍信息")
    @Parameter(name = "studentAddDormDTO", description = "添加学生宿舍信息")
    @PutMapping
    public Result addStudentDorm(@RequestBody StudentDormDTO studentDormDTO){
        log.info("添加学生宿舍信息:{}", studentDormDTO);
        dormSharedService.addStudentDorm(studentDormDTO);
        return Result.success();
    }

    /**
     * 移除学生宿舍信息
     * @return
     */
    @Operation(summary = "移除学生宿舍信息")
    @Parameter(name = "id", description = "学生id")
    @DeleteMapping("/{id}")
    public Result deleteStudentDorm(@PathVariable(name = "id") Long studentId){
        log.info("移除宿舍学生信息：{}", studentId);
        dormSharedService.deleteStuInfo(studentId);
        return Result.success();
    }
}
